#include "Text.h"
#include "common.h"
#include "Container.h"

using namespace std;

Text::Text(Container* parent, string name, string label, int x, int y, int h) {
    this->parent = parent;
    
    this->name = name;
    this->x = x;
    this->y = y;
    this->h = h;
    
    this->label = label;
    
    police = TTF_OpenFont("times.ttf", h);
    couleur = SDL_Color();
    couleur.r = 0;
    couleur.g = 0;
    couleur.b = 0;
    
    SDL_render = NULL;
}

SDL_Surface* Text::updateRender() {
    SDL_FreeSurface(SDL_render);
    
    SDL_render = TTF_RenderText_Blended(police, label.c_str(), couleur);
    return SDL_render;
}

void Text::setLabel(string value) {
    label = value;
    parent->callUpdateRender();
}

/*
 * Accesseur
 */
string Text::getName() {
    return name;
}

string Text::getLabel() {
    return label;
}

int Text::getx() {
    return x;
}

int Text::gety() {
    return y;
}